//
//  CSTabBarController.m
//  classroom
//
//  Created by Macx on 16/7/30.
//  Copyright © 2016年 LiuZhuo. All rights reserved.
//

#import "CSTabBarController.h"
#import "CSHomeTableViewController.h"
#import "CSSettingTableViewController.h"
#import "CSPhotoTableViewController.h"
#import "CSNavigationController.h"

@interface CSTabBarController ()
@property(nonatomic,strong)CSHomeTableViewController *home;
@property(nonatomic,strong)CSPhotoTableViewController *photo;
@property(nonatomic,strong)CSSettingTableViewController *setting;
@end

@implementation CSTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
+(void)initialize{
    
}
-(instancetype)init{
//-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    
//    if (self==[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    if (self = [super init]) {
     
        // 初始化根控制器
        self.home =(CSHomeTableViewController *) [self setViewControllerWith:@"CSHomeTableViewController" title:@"首页" image:@"tabbar_home" selectedImage:@"home1"];
        self.photo = (CSPhotoTableViewController *) [self setViewControllerWith:@"CSPhotoTableViewController" title:@"平面图" image:@"pingc"  selectedImage:@"tu1"];
        self.setting =  (CSSettingTableViewController *)  [self setViewControllerWith:@"CSSettingTableViewController" title:@"我" image:@"tabbar_profile"  selectedImage:@"aa"];
        // 只读属性 不能赋值
        //    tabbar.childViewControllers=@[home,message,discover,profile];
        
//                self.viewControllers=@[self.home,self.photo,self.setting];
        
    }
    return self;
  
}

-(UIViewController *)setViewControllerWith:(NSString *)name title:(NSString *)title image:(NSString *)imgeName selectedImage:(NSString *)selectedImage{
    UIStoryboard * sb = [UIStoryboard storyboardWithName:name bundle:nil];
    UIViewController * vc = [sb instantiateInitialViewController];
    vc.tabBarItem.title=title;
    vc.navigationItem.title = title;
    vc.tabBarItem.image= [ UIImage imageNamed:imgeName];
    UIImage * selectImage = [UIImage imageNamed:selectedImage];
    selectImage = [ selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage=selectImage;
//        vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:255/255.0];
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:0/255.0 green:155/255.0 blue:238/255.0 alpha:1.0]} forState:UIControlStateSelected];
    CSNavigationController * nav = [[CSNavigationController alloc]initWithRootViewController:vc];
    [self addChildViewController:nav];
    return vc;
}


@end
